package com.ruoyi.result.awardStudent.mapper;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.result.awardStudent.domain.ResultStudentAward;
import com.ruoyi.result.awardStudent.domain.dto.ResultStudentAwardDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 学生获奖信息Mapper接口
 *
 * @author ruoyi
 * @date 2025-01-14
 */
@Mapper
public interface ResultStudentAwardMapper extends BaseMapper<ResultStudentAward>
{
    /**
     * 查询学生获奖信息
     *
     * @param id 学生获奖信息主键
     * @return 学生获奖信息
     */
    public ResultStudentAward selectResultStudentAwardById(Long id);

    /**
     * 查询学生获奖信息列表
     *
     * @param resultStudentAward 学生获奖信息
     * @return 学生获奖信息集合
     */
    public List<ResultStudentAward> selectResultStudentAwardList(ResultStudentAwardDTO resultStudentAward);

    /**
     * 新增学生获奖信息
     *
     * @param resultStudentAward 学生获奖信息
     * @return 结果
     */
    public int insertResultStudentAward(ResultStudentAward resultStudentAward);

    /**
     * 修改学生获奖信息
     *
     * @param resultStudentAward 学生获奖信息
     * @return 结果
     */
    public int updateResultStudentAward(ResultStudentAward resultStudentAward);

    /**
     * 删除学生获奖信息
     *
     * @param id 学生获奖信息主键
     * @return 结果
     */
    public int deleteResultStudentAwardById(Long id);

    /**
     * 批量删除学生获奖信息
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteResultStudentAwardByIds(Long[] ids);

    List<ResultStudentAward> selectResultStudentAwardByIds(Long[] ids);

    @Select("SELECT COUNT(*) FROM result_student_award WHERE sync_status = '是' AND is_deleted = 0")
    long selectCount();

    @Select("SELECT YEAR(award_time) as year, COUNT(*) as count FROM result_student_award " +
            "WHERE is_deleted = 0 " +
            "GROUP BY YEAR(award_time) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYear();

    @Select("SELECT YEAR(award_time) as year, COUNT(*) as count FROM result_student_award " +
            "WHERE is_deleted = 0 AND user_id = #{userId} " +
            "GROUP BY YEAR(award_time) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYearAndUserId(@Param("userId") Long userId);

    List<ResultStudentAward> selectResultStudentAwardListByDept(ResultStudentAwardDTO resultStudentAward);
}
